<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的钱包</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../css/center.css">
    <link rel="stylesheet" type="text/css" href="../css/my.css">
    <link rel="stylesheet" type="text/css" href="../css/common.css">
    <style type="text/css">
      .aui-list{background: transparent;border:none;}
      .aui-list .aui-list-item{background: #f7f7f7;border-radius: .3rem;padding-top: 3px;padding-bottom: 3px;border:none;}
      .aui-list .aui-list-header{background:transparent;color: #808080;justify-content:left;}
      .aui-list .aui-list-item-input.headimg{text-align: right;width: auto;}
      .headimg img{width: 2rem;height: 2rem;}
      .aui-radio:checked{background-color: #f0392b;border-color: #f0392b;}
    </style>
</head>
<body class="bg-white">
<!-- 顶部 -->
<header class="aui-bar aui-bar-nav bg_color tb_top_bar jb">
    <div class="aui-title"></div>
    <a class="aui-pull-right aui-btn aui-btn-outlined" onclick="openPublic(this)" data-frame="money_logs_frm" data-title="钱包明细" tapmode>
        明细
    </a>
</header>
<!-- 顶部end -->
<!-- 头部 -->
<div class="srbb_top_bar bg_color jb">
     <div class="srbb_top_round1">
         <div class="srbb_top_round2">
              <p id="money">0</p>
              <span class="aui-font-size-12">可提现</span>
         </div>
     </div>
</div>
<!-- 头部 end -->
<!-- 结算 -->
<section class="aui-grid srbb_sy">
 <div class="aui-row">
    <div class="aui-col-xs-6">
        <span id="money_ing">0</span>
        <div class="aui-grid-label">提取中</div>
    </div>
    <div class="aui-col-xs-6">
        <span id="money_has">0</span>
        <div class="aui-grid-label">已提取</div>
    </div>
 </div>
</section>
<!-- 结算end -->
<!-- 支付宝提现 -->
<div class="srbb_dd_bar">
    <div class="aui-info">
         <div class="aui-info-item">
             <img src="../image/tit_left.png">
             <div class="aui-margin-l-5"><h3>请选择提现方式</h3></div>
         </div>
    </div>
    <div class="aui-content-padded aui-margin-t-15 alipay" onclick="openPublic(this)" data-frame="bind_alipay_frm" data-title="绑定支付宝">
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item bg-white">
                <div class="aui-list-item-label-icon aui-padded-5">
                    <img src="../image/alipay.png" width="40">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow" id="alipay_text">
                    请添加支付宝账户
                </div>
            </li>
        </ul>
    </div>
    <!-- <div class="aui-content-padded aui-margin-t-15 wechat" data-has="0" onclick="bind_wechat()" tapmode>
        <ul class="aui-list aui-list-in">
            <li class="aui-list-item bg-white">
                <div class="aui-list-item-label-icon aui-padded-5">
                    <img src="../image/share/wx.png" width="40">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow" id="wechat_text">
                    请绑定微信
                </div>
            </li>
        </ul>
    </div> -->
    <div class="aui-content-padded aui-margin-b-15">
      <ul class="aui-list aui-form-list">
          <li class="aui-list-item bg-white">
              <div class="aui-list-item-inner">
                  <div class="aui-list-item-label">
                      请选择:
                  </div>
                  <div class="aui-list-item-input">
                    <label><input class="aui-radio" type="radio" name="type" value="1" checked> 支付宝 </label>
                    <!-- <label>&nbsp;&nbsp;&nbsp;<input class="aui-radio" type="radio" name="type" value="0"> 微信</label> -->
                  </div>
              </div>
          </li>
          <li class="aui-list-header"></li>
          <li class="aui-list-item">
              <div class="aui-list-item-inner">
                  <div class="aui-list-item-label">
                      提现金额：
                  </div>
                  <div class="aui-list-item-input">
                      <input type="number" value="" name="money">
                  </div>
              </div>
          </li>
          
      </ul>
    </div>
    <div class="aui-content-padded aui-margin-t-15">
       <div class="aui-btn aui-btn-block tuichu jb aui-btn-danger" onclick="draw()" tapmode >确认提交</div>
    </div>
    <section class="aui-content">
        <div class="aui-card-list">
            <div class="aui-text-danger aui-padded-l-15">
               提现说明: 
            </div>
            <div class="aui-card-list-content-padded" id="intro">
              
            </div>
        </div>
    </section>


</div>
</body>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
    apiready = function(){
      api.parseTapmode();
      //获取提现配置
      getCfg();
      //监听绑定支付宝 
      _AddEventListener('bind_alipay', function(ret) {
          //刷新
          getCfg();
      });
    };
    function getCfg(){
      _loading2();
      _Ajax(window.APIServer.DrawCfg,'post',{},'json',function(ret){
        _loading2_close();
        if (ret.code==1) {
          $('#money').text(ret.data.money||'0');
          $('#money_ing').text(ret.data.money_ing||'0');
          $('#money_has').text(ret.data.money_has||'0');
          $('#intro').html(ret.data.intro);
          if (ret.data.alipay_account!='') {
              $('#alipay_text').text(ret.data.alipay_account);
          }
          if (ret.data.is_bind_wx!=0) {
              $('#wechat_text').html(ret.data.is_bind_wx);
              $('.wechat').attr('data-has','1');
          }
        }else{
          _toast('拉取信息失败');
        }
      })
    }
    //提现提交
    function draw(){
      var money = $('input[name=money]').val();
      if (money=='') {
        _toast('请输入提现金额');
        return false;
      }
      var type = $('input[name=type]:checked').val();
      if (type=='') {
        _toast('请选择提现方式');
        return false;
      }
      _loading('正在提取中','',true);
      _Ajax(window.APIServer.Draw,'post',{values:{money:money,type:type}},'json',function(ret){
        _loading_close();
        _toast(ret.msg);
        if (ret.code==1) {
          $('input[name=money]').val('');
          //刷新
          setTimeout(function() {
              getCfg();
          }, 1000)
        }
        
      })
    }
    //绑定微信
    function bind_wechat(){
        var has = $('.wechat').data('has');
        if (has==1) {
          return false;
        }
        var wx = api.require('wx');
        //是否安装客户端
        wx.isInstalled(function(ret, err) {
            if (!ret.installed) {
                alert('您还没安装微信客户端');
                return false;
            }else{
                //step1 获取code...
                wx.auth({
                    apiKey: ''
                }, function(ret, err) {
                    //step get access_token
                    if (ret.status) {
                        _loading('登录中...','',true);
                        wx.getToken({
                            apiKey: '',
                            apiSecret: '',
                            code: ret.code
                        }, function(ret, err) {
                            if (ret.status) {
                                //step3 getuserinfo
                                wx.getUserInfo({
                                    accessToken: ret.accessToken,
                                    openId: ret.openId
                                }, function(ret, err) {
                                    if (ret.status) {
                                        //last 提交服务器验证
                                        var uinfo = ret;
                                        _Ajax(window.APIServer.BindWechat,'post',{values:uinfo},'json',function(ret){
                                            _loading_close();
                                            if (ret.code==1) {
                                                //广播事件：用户绑定微信成功
                                                _SendEvent('bind_mobile_wechat');
                                                getCfg();
                                                _toast('绑定成功！');
                                            }else{
                                                _toast(ret.msg);
                                            }

                                        });
                                    } else {
                                        _loading_close();
                                        _toast('获取信息失败');
                                    }
                                });
                            } else {
                                _loading_close();
                                _toast('绑定失败');
                            }
                        });
                    } else {
                        var code_arr = {'-1':'未知错误','1':'您取消了登录','2':'您拒绝了登录','3':'微信未安装'};
                        _toast(code_arr[err.code]);
                    }
                });
            }
        });

    }
</script>
</html>
